package com.szsfm.vehiclemanagement.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.orhanobut.logger.Logger;
import com.szsfm.vehiclemanagement.R;
import com.szsfm.vehiclemanagement.adapter.MessageAdapter;
import com.szsfm.vehiclemanagement.base.BaseFragment;
import com.szsfm.vehiclemanagement.bean.Message;
import com.szsfm.vehiclemanagement.mvp.presenter.MessagePresenter;
import com.szsfm.vehiclemanagement.mvp.view.IMessageView;
import com.szsfm.vehiclemanagement.util.ToastUtil;

import java.util.List;


public class MessageFragment extends BaseFragment implements IMessageView {

    RecyclerView mRecycleView;
    MessageAdapter mAdapter;
    Context mContext;
    MessagePresenter messagePresenter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View contentView = inflater.inflate(R.layout.fragment_message,container,false);
        Logger.d("this ="+this);
        mContext = getActivity();
        mRecycleView = contentView.findViewById(R.id.msg_recycler_view);
        mRecycleView.setLayoutManager(new LinearLayoutManager(mContext));
        messagePresenter = new MessagePresenter(this);
        messagePresenter.getMessage();
        return contentView;
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void startLoadData() {
        ToastUtil.show("正在请求消息");
    }

    @Override
    public void loadDataFinish(List<Message> messages) {
        mAdapter = new MessageAdapter(mContext,messages);
        mRecycleView.setAdapter(mAdapter);
    }
}
